package ExceptionTest;

import java.io.FileInputStream;

/*
如何自定义一个异常?
    1.编写一个类继承Exception或者RuntimeException
    2.提供有参无参构造方法

 */
public class ExceptionTest4 {
    public static void main(String[] args){
        //处理异常
        try{
            int sum1 = mySum(200,100);
            System.out.println(sum1);
        }catch(MyException me){
            me.printStackTrace();
        }
    }
    public static int mySum(int x, int y) throws MyException{
        if(x < y){
            //抛出一个异常
            throw new MyException("数字大小错误");
        }
        return x+y;
    }
}
class MyException extends Exception{
    public MyException(){
        super();
    }

    public MyException(String s){
        super(s);
    }
}
